You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Pull Request introduces Picture-in-Picture (PiP) mode to the ComposeMediaPlayer library. This feature allows users to continue watching video content in a floating window while navigating away from the application on mobile devices.
📱 Supported Platforms
Platform
Status
Notes
Android
✅
Fully supported using native Android PiP APIs (requires Android 8.0+).
iOS
✅
Fully supported using AVPictureInPictureController.
Desktop
❌
Not supported (No-op).
Web
❌
Not supported (No-op).
🛠 Implementation Details
Common Code
Introduced a platform-agnostic interface to handle PiP requests.
Added logic to gracefully handle PiP triggers on unsupported platforms (no-op).
Android
Enabled android:supportsPictureInPicture="true" in the manifest.
Implemented something similar toonUserLeaveHint to automatically enter PiP mode when the user backgrounds the app while video is playing.
Configured PictureInPictureParams to handle aspect ratio updates dynamically based on the video content.
iOS
Integrated AVPictureInPictureController with the existing AVPlayer layer.
Handled the restoration of the user interface when returning from PiP mode.
🧪 How to Test
Android
Launch the app and start playing a video.
Press the Home button or swipe up to go home.
Expectation: The app minimizes into a floating PiP window, and the video continues playing.
Tap the PiP window to expand it back to full screen.
iOS
Launch the app and start playing a video.
Swipe up to go home or tap the PiP toggle button.
Expectation: The video detaches into a floating overlay, and playback continues.
Lock the screen and verify audio continues playing.
📸 Screenshots / Screen Recordings
(Please attach screenshots or a GIF/video of the PiP transition on Android and iOS here)
⚠️ Notes
Android: Min SDK is set to 23, but PiP requires API 26+. Checks are in place to ensure safety on older devices.
iOS: Requires "Audio, AirPlay, and Picture in Picture" to be enabled in the Background Modes capability.
Hi!
Are you sure that PiP functionality should be part of VideoPlayerState? In its current form, this might be a bit misleading, since PiP is only available on Android and iOS.
It might be cleaner to extract them into a separate entity - e.g. PictureInPictureController - and publish it as separate artifact with clear note that its supported only on Android and iOS.
A similar approach is used in my project, you can find the implementation here: PictureInPicture.kt
@xephosbot Yes, I like your approach. I initially created the controller at the beginning, but since I inject it into the video player, that makes it unnecessary. However, injecting the player into the PiP controller would make more sense. Thanks for your comment 🙌
Thank you very much, sorry for the delay, but it's merged!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Feature - Picture-in-Picture (PiP) Support
📝 Description
This Pull Request introduces Picture-in-Picture (PiP) mode to the
ComposeMediaPlayerlibrary. This feature allows users to continue watching video content in a floating window while navigating away from the application on mobile devices.📱 Supported Platforms
AVPictureInPictureController.🛠 Implementation Details
Common Code
Android
android:supportsPictureInPicture="true"in the manifest.onUserLeaveHintto automatically enter PiP mode when the user backgrounds the app while video is playing.PictureInPictureParamsto handle aspect ratio updates dynamically based on the video content.iOS
AVPictureInPictureControllerwith the existingAVPlayerlayer.🧪 How to Test
Android
iOS
📸 Screenshots / Screen Recordings
(Please attach screenshots or a GIF/video of the PiP transition on Android and iOS here)